<?php
	require_once('include/hostmon_client.php');
	require_once('config.inc.php');

	if(isset($_POST)){
		$dom_account['dom'] = $_POST['dom'];
		$dom_account['password'] = $_POST['password'];
		$client = new HostmonsterClient($dom_account['dom'], $dom_account['password'],$dom_manager_login_url, $check_domain_url);
		// login cpanel
		if(!$client->login_domain_manager()){
			echo date("d/m/y H:i:s") . " | " . "Error: " . $client->get_error_message() . "<br>";
			exit;
		}else{
			// check domain
			echo "<div><hr><h3>Check domain: " . $_POST['dom_to_check'] . "</h3></div>";
			if(isset($_POST['dom_to_check'])){
				if($client->check_dom($_POST['dom_to_check'], $msg)!== false){
					echo $msg;
				}else{
					echo "<br><h4>Failed to verify. Error:</h4> " . $msg;
				}
			}
			//add domain
			echo "<div><hr><h3>Add domain: " . $_POST['dom_to_add'] . "</h3></div>";
			if(!$client->add_dom($_POST['dom_to_add'], $_POST['dom_type'], $_POST['dom_owner'], $_POST['assign_type'], $_POST['dir'], $_POST['sub'], $msg)){
				echo "<br><h4>Failed to add the domain. Message:</h4> " . $msg;
			}else{
				echo "<br><h4>The domain was added. Message: </h4>". $msg;
			}
			//retrieve domain list of the account
			echo "<div><hr><h3>Domain list: </h3></div>";
			$doms = $client->get_domain_list($msg);
			if($doms == NULL){
				echo $msg;
			}else{
				foreach($doms as $dom){
					echo "<div> dom name: " . $dom['name'];
					echo "<br>status: " . $dom['status']."<br>---</div>";
				}
			}
			//unassign a domain
			echo "<div><hr><h3>Unassign domain: </h3></div>";
			if($client->unassign($_POST['dom_to_unassign'], $msg) == false){
				echo "<br><h4>Failed to unassined the domain. Message:</h4> " . $msg;
			}else{
				echo "<br><h4>The domain was unassigned. Message: </h4>". $msg;
			}
			//unassign a domain
			echo "<div><hr><h3>Remove domain: </h3></div>";
			if($client->remove($_POST['dom_to_remove'], $msg) == false){
				echo "<br><h4>Failed to remove the domain. Message:</h4> " . $msg;
			}else{
				echo "<br><h4>The domain was removed. Message: </h4>". $msg;
			}

		}
	}

